import json
import os
import shutil

filepathdir = "D:\\download\\sipopatent\\download\\cover"
filepathdir2 = "D:\\download\\sipopatent\\download\\cover2"

def get_files():
    for path, dirNames, fileNames in os.walk(filepathdir):
        # 获取当前目录的所有文件
        for fileName in fileNames:
            yield os.path.join(path, fileName)

for filepath in get_files():
    print(filepath)
    filename = filepath.split(os.sep)[-1]
    filename_no_suf = os.extsep.join(filename.split(os.extsep)[:-1])
    dirname = filename_no_suf[:-4]
    outpath = os.path.join(filepathdir2, dirname)
    if not os.path.exists(outpath):
        os.makedirs(outpath)
    coveruri = "/smartlib/sipopatent/"+dirname+"/"+str(filename)
    jsondict={}
    jsondict["identifier_pissn"] = filename_no_suf
    jsondict["coveruri"] = coveruri
    print(jsondict)
    with open("jsoncoveruri.big_json", mode='a', encoding='utf-8') as f:
        line = json.dumps(jsondict, ensure_ascii=False).strip() + '\n'
        f.write(line)
    shutil.move(filepath, outpath)
    # print(outpath)
